package com.groupfifteen.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.groupfifteen.entity.SysFillQuestionEntity;
import com.groupfifteen.entity.SysJudgeQuestionEntity;
import com.groupfifteen.entity.SysMultiQuestionEntity;
import com.groupfifteen.vo.AnswerVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface AnswerDao {
    /**
     * 查询题库 分页
     *
     * @param page 分页对象
     * @param subject 学科
     * @param section 章节
     * @param question 问题
     * @return 题目
     */
    @Select("select question_id, question, subject, score, section,level, \"选择题\" as type from sys_multi_question where question like concat('%',#{question},'%') and subject like concat('%',#{subject},'%') and section like concat('%',#{section},'%')" +
            "union select question_id,question, subject, score, section,level, \"判断题\" as type  from sys_judge_question where question like concat('%',#{question},'%') and subject like concat('%',#{subject},'%') and section like concat('%',#{section},'%')" +
            "union select question_id,question, subject, score, section,level, \"填空题\" as type from sys_fill_question where question like  concat('%',#{question},'%') and subject like concat('%',#{subject},'%') and section like concat('%',#{section},'%')")
    IPage<AnswerVo> findAll(Page<AnswerVo> page, @Param("subject") String subject, @Param("section") String section, @Param("question") String question);


    /**
     * 查选择题
     *
     * @param questionId 选择题id
     * @return 选择题
     */
    @Select("select question_id, subject, question, answer_a, answer_b, answer_c, answer_d, right_answer, section, level, analysis from sys_multi_question where question_id = #{questionId}")
    SysMultiQuestionEntity findMultiQuestionById(Long questionId);

    /**
     * 查填空题
     *
     * @param questionId 题目id
     * @return 填空题
     */
    @Select("select question_id, subject, question, answer, analysis, level, section from sys_fill_question where question_id = #{questionId}")
    SysFillQuestionEntity findFillQuestionById(Long questionId);

    /**
     * 查判断题
     *
     * @param questionId 题目id
     * @return 判断题
     */
    @Select("select question_id, subject, question, answer, analysis, level, section from sys_judge_question where question_id = #{questionId}")
    SysJudgeQuestionEntity findJudgeQuestionById(Long questionId);

}
